package com.ibeifeng.crm.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ibeifeng.crm.bean.Log;
import com.ibeifeng.crm.service.GetLogService;


@Controller
@RequestMapping("/log/")
public class GetLogController {
	Logger logger=Logger.getLogger(GetLogController.class);
	@Resource
	GetLogService getLogService;
	@RequestMapping(value="queryAll", produces = "application/json; charset=utf-8")
	public @ResponseBody String mquery(HttpServletRequest request, HttpServletResponse response){
		String pg = request.getParameter("page");
		String pgSize = request.getParameter("rows");
		String keyWord=request.getParameter("keyWord");
		// 若要显示的第几页为空，那么默认为1
		if (null == pg || "".equals(pg)) {
			pg = "1";
		}
		// 显示多少行为空，那么默认为10
		if (null == pgSize || "".equals(pgSize)) {
			pgSize = "5";
		}		
		List<Log> list = getLogService.queryLimit(Integer.parseInt(pg), Integer.parseInt(pgSize),keyWord);
		int count=getLogService.count();
		Map m=new HashMap();
		if(count>0){
			m.put("total", count);
		}else{
			m.put("total", 1);
		}
		
		m.put("rows", list);
		JSONArray js=JSONArray.fromObject(m);
		String j=js.toString();
		String jz=j.substring(1, j.length()-1);
		return jz;
	}
	
}
